<script setup lang="ts">
import {ref} from "vue";
const showIndex = ref(0)
let liList = ['全部', '后端技术', '前端技术', '小记', '随笔']
const map = new Map().set('全部', null).set('后端技术', 1).set('前端技术', 2).set('小记', 11).set('随笔', 10)
function changeIndex(index: number, item: string) {
  showIndex.value = index
  emit('changeCategory', {categoryId: map.get(item), current:1, size:10})
}
const emit = defineEmits(['changeCategory'])
</script>

<template>
  <div class="category">
    <ul>
      <li v-for="(item,index) in liList" :key="index"
          :class="{selected: index === showIndex}"
          @click="changeIndex(index, item)"
      >{{ item }}</li>
    </ul>
  </div>
</template>

<style scoped lang="less">
.category {
  width: 100%;
  height: 48px;
  border-radius: 8px;
  background: #ffffff;
  ul {
    display: flex;
    justify-content: space-between;
    list-style: none; /* 移除列表样式 */
    padding: 0 16px;
    li {
      width: 180px;
      height: 32px;
      margin: 8px 0;
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #333333;
      font-size: 14px;
      transition: all 0.3s; // 渐变
      &:hover{
        cursor: pointer;
        color: #EB5C88;
      }
      &.selected {
        background: #FCEDF2;
        color: #EB5C88;
      }
    }
  }
}
@media screen and (max-width: 768px) {
  .category {
    ul {
      li {
        width: 60px;
      }
    }
  }
}
@media screen and (min-width: 1600px) {
  .category ul li {
    width: 220px;
  }
}
</style>
